<?php

declare(strict_types=1);

namespace App\Listener;

use App\Model\ChatRoom;
use App\Model\ChatRoomGift;
use Hyperf\Event\Annotation\Listener;
use Psr\Container\ContainerInterface;
use Hyperf\Event\Contract\ListenerInterface;

#[Listener]
class ChatRoomSendGiftListener implements ListenerInterface
{
    public function __construct(protected ContainerInterface $container)
    {
    }

    public function listen(): array
    {
        return [
            \App\Event\ChatRoomSendGiftNotify::class,
        ];
    }

    public function process(object $event): void
    {
        $item = $event->item;
        logInfo('chat_room_send_gift', $item);
        ChatRoomGift::query()->insert($item);
        ChatRoom::query()->where('room_number', $item['room_number'])->increment('heat', $item['cost']);

    }
}
